#include "ultimateguiofdoom.h"
UltimateGUIofDoom::UltimateGUIofDoom(QWidget *parent, Qt::WFlags flags)
	: QMainWindow(parent, flags)
{
	ui.setupUi(this);

	connect(ui.list_Solut,SIGNAL(currentRowChanged(int)),this,SLOT(onSolutionChange(int)));
	wgets.append(new combinations());
	wgets.append(new BernulliWidget());
	wgets.append(new PolinomWidget());
	wgets.append(new puasson());
	wgets.append(new MuavrLocal());
	if(ParserLibClass::getFuncValue!=NULL)
		wgets.append(new MuavrIntegral());
	wgets.append(new BinominalDistribution());
	wgets.append(new geometr());
	wgets.append(new Hypergeom());
	wgets.append(new discreteChar());
	if(ParserLibClass::getFuncValue!=NULL)
		wgets.append(new DeviationCont());
	for(QList<newInterface*>::iterator i=wgets.begin();i!=wgets.end();i++)
	{
		qint32 index=ui.frame_Container->addWidget(*i);
		ui.list_Solut->addItem((*i)->name());
		ui.list_Solut->item(ui.list_Solut->count()-1)->setData(Qt::UserRole,QVariant(index));
	}


}

UltimateGUIofDoom::~UltimateGUIofDoom()
{

}
void UltimateGUIofDoom::onSolutionChange(int row)
{
	qint32 index=ui.list_Solut->item(row)->data(Qt::UserRole).toInt();
	ui.frame_Container->setCurrentIndex(index);
	disconnect(ui.calcButton,0,0,0);
	disconnect(ui.helpButton,0,0,0);
	connect(ui.calcButton,SIGNAL(clicked()),ui.frame_Container->widget(index),SLOT(calc()));
	connect(ui.helpButton,SIGNAL(clicked()),ui.frame_Container->widget(index),SLOT(showHelp()));
	this->resize(this->childrenRect().size());

}

void UltimateGUIofDoom::closeEvent(QCloseEvent* event)
{
	QCoreApplication::quit();

}